<?php

namespace app\admin\model;

use app\common\model\TimeModel;

use app\admin\model\OtherLwf;
use app\admin\model\OtherZcf;
use app\admin\model\OtherCyl;
use app\admin\model\BenefitZcf;

class BenefitWellNumber extends TimeModel
{

    protected function getOptions(): array
    {
        return [
            'name'       => "benefit_well_number",
            'deleteTime' => false,
            'createTime' => false,
            'updateTime' => false,
        ];
    }

    public static array $notes = [];
    private array $type_array = ['JGG', 'JXJGJ'];
    private array $price_array = [6.86, 8.95, 15, 20, 30, 48, 58, 88];

    public function getBeforeCapacityAttr($value)
    {
        return $value + 0;
    }

    public function getAfterCapacityAttr($value)
    {
        return $value + 0;
    }

    public function getCapacityDifferenceAttr($value)
    {
        return $value + 0;
    }

    public function getDifferenceBenefitAttr($value)
    {
        return $value + 0;
    }

    public function getNormalLaborCostAttr($value)
    {
        return $value + 0;
    }

    public function getSelfLaborCostAttr($value)
    {
        return $value + 0;
    }

    public function getOtherLaborCostAttr($value)
    {
        return $value + 0;
    }

    public function getMaterialCostAttr($value)
    {
        return $value + 0;
    }

    public function getBenefitAttr($value)
    {
        return $value + 0;
    }

    //关联产液量
    public function cyl()
    {
        return $this->hasMany(OtherCyl::class, 'JH', 'well_number')->whereRaw('TO_NUMBER(RCYL1) > 0')->field(['JH, RCYL1, HS', "TO_CHAR(RQ, 'YYYY-MM-DD') AS RQ"]);
    }

    //材料费
    public function clf()
    {
        return $this->hasMany(OtherZcf::class, 'F_JH', 'well_number')->field('F_FLSJ, F_JH,F_DJ, F_JE,F_TYPE');
    }

    //劳务费    
    public function lwf()
    {
        return $this->hasMany(OtherLwf::class, 'F_GCMC', 'well_number')->field('F_GCBH, F_GCMC, F_KGRQ, F_WGRQ, F_DMBTR');
    }

    //自营劳务费    
    public function zylwf()
    {
        return $this->hasMany(BenefitZcf::class, 'F_JH', 'well_number')->whereIn('F_TYPE', $this->type_array)
            ->whereIn('F_DJ', $this->price_array);
    }

    //外部劳务费    
    public function wblwf()
    {
        return $this->hasMany(BenefitZcf::class, 'F_JH', 'well_number')->whereIn('F_TYPE', $this->type_array)
            ->whereNotIn('F_DJ', $this->price_array);
    }
}
